package com.dididoctor.doctor.Activity.Usercentre.MyPurse;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.dididoctor.doctor.Activity.Usercentre.MyPurse.ChoicePayWay.PayWayActivity;
import com.dididoctor.doctor.Activity.Usercentre.MyPurse.CollectionMethods.CollectionMethodsActivity;
import com.dididoctor.doctor.Activity.Usercentre.MyPurse.InComeList.ComeInActivity;
import com.dididoctor.doctor.Activity.Usercentre.MyPurse.WithdrawList.WithDrawListActivity;
import com.dididoctor.doctor.Bean.Token;
import com.dididoctor.doctor.Dialog.CashDialog;
import com.dididoctor.doctor.Dialog.TipTimeDialog;
import com.dididoctor.doctor.MV.EduActivity;
import com.dididoctor.doctor.R;
import com.dididoctor.doctor.Utils.Util;

/**
 * Created by boy on 2016/4/22.
 */
public class MyPurseActivity extends EduActivity implements MyPurseView {
    private TextView mTvGeneralIncome, mTvBalance, mTvMincome;

    private TextView mTvTitle;
    private ImageView mBtnBack;
    private MypursePresenter Presenter;

    private RelativeLayout mRlApprove;
    private TextView mTvCancel, mTvConfirm;
    private boolean agree = false;
    private String remainTime = " ";
    private String balance = "";
    private MyPurse finalPurse;

    @Override
    public void setContentLayout() {
        setContentView(R.layout.activity_mypurse);
    }

    @Override
    public void init() {
        /**头部**/
        initTitleView();

        initView();
    }

    private void initView() {
        mTvGeneralIncome = (TextView) findViewById(R.id.tv_general_income);//总收入
        mTvBalance = (TextView) findViewById(R.id.tv_balance);//账户余额
        mTvMincome = (TextView) findViewById(R.id.et_mincome);//当前月收入
        mRlApprove = (RelativeLayout) findViewById(R.id.rel_approve);
        String show = Token.getIsPass();
        if (show.equals("3")) {
            mRlApprove.setVisibility(View.GONE);
        }

        findViewById(R.id.rel_deposit).setOnClickListener(this);
        findViewById(R.id.rel_collection_methods).setOnClickListener(this);
        findViewById(R.id.rel_withdraw_list).setOnClickListener(this);
        findViewById(R.id.rel_income_list).setOnClickListener(this);
        findViewById(R.id.tv_cancel).setOnClickListener(this);
        findViewById(R.id.tv_confirm).setOnClickListener(this);

        Presenter = new MypursePresenter(this, this);
    }

    @Override
    protected void onResume() {
        Presenter.lunch();
        super.onResume();
    }

    private void initTitleView() {
        mTvTitle = (TextView) findViewById(R.id.tv_title);
        mTvTitle.setText("我的钱包");
        mBtnBack = (ImageView) findViewById(R.id.btn_back);
    }

    @Override
    public void onClickEvent(View view) {

        switch (view.getId()) {
            case R.id.rel_deposit://提现  1.比对时间是否到了取款时间  2.比对是否有收款方式  3.输入金额进入到选择收款方式
                //一句话描述和提现信息dialog

                if (agree) {
                    if (!Util.isEmpty(balance)) {
                        CashDialog dialog = new CashDialog(MyPurseActivity.this, balance);
                        dialog.show();
                    } else {
                        CashDialog dialog = new CashDialog(MyPurseActivity.this, "0");
                        dialog.show();
                    }
                } else {
                    TipTimeDialog dialog = new TipTimeDialog(
                            MyPurseActivity.this, remainTime);
                    dialog.show();
                }

//                提现成功失败界面
//                ComeInResultActivity
                break;
            case R.id.rel_collection_methods://设置收款方式
                Intent intent = new Intent(MyPurseActivity.this, CollectionMethodsActivity.class);
                startActivity(intent);
                break;
            case R.id.rel_withdraw_list://提现清单
                Intent withDrawintent = new Intent(MyPurseActivity.this, WithDrawListActivity.class);
                startActivity(withDrawintent);
                break;
            case R.id.rel_income_list://收入清单
                Intent ComeInintent = new Intent(MyPurseActivity.this, ComeInActivity.class);
                startActivity(ComeInintent);
                break;
            case R.id.tv_confirm:
                MyPurseActivity.this.finish();
                break;
            case R.id.tv_cancel:
                MyPurseActivity.this.finish();
                break;
        }

    }

    @Override
    public void getpursefail() {

    }

    @Override
    public void getpursesucced(MyPurse myPurse) {
        if (myPurse != null) {
            finalPurse = myPurse;
            mTvGeneralIncome.setText(myPurse.getAmount());
            mTvBalance.setText(myPurse.getBalance());
            mTvMincome.setText(myPurse.getMonth());
            balance = myPurse.getBalance();
            remainTime = myPurse.getRemainTime();
            if (remainTime == null || remainTime.equals("")) {
                agree = true;
            } else {
                agree = false;
            }
        }
    }

    @Override
    public void withDrawals(String cash) {
        //0未绑卡，1绑卡
        if (finalPurse.getHasCard().equals("0")) {
            Intent intent = new Intent(MyPurseActivity.this, CollectionMethodsActivity.class);
            startActivity(intent);
        } else {
            Intent intent2 = new Intent(MyPurseActivity.this, PayWayActivity.class);
            intent2.putExtra("balance", cash);
            startActivity(intent2);
        }
    }
}
